package cn.stylefeng.guns.modular.sysuser.controller;

import cn.stylefeng.guns.modular.sysuser.pojo.request.SysUserRequest;
import cn.stylefeng.guns.modular.sysuser.service.SysUserService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统用户控制器
 *
 * @author zhu
 * @date 2021/10/21 18:35
 */
@RestController
@ApiResource(name = "系统用户")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 添加
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @PostResource(name = "添加", path = "/sysUser/add")
    public ResponseData add(@RequestBody @Validated(SysUserRequest.add.class) SysUserRequest sysUserRequest) {
        sysUserService.add(sysUserRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @PostResource(name = "删除", path = "/sysUser/delete")
    public ResponseData delete(@RequestBody @Validated(SysUserRequest.delete.class) SysUserRequest sysUserRequest) {
        sysUserService.del(sysUserRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @PostResource(name = "编辑", path = "/sysUser/edit")
    public ResponseData edit(@RequestBody @Validated(SysUserRequest.edit.class) SysUserRequest sysUserRequest) {
        sysUserService.edit(sysUserRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @GetResource(name = "查看详情", path = "/sysUser/detail")
    public ResponseData detail(@Validated(SysUserRequest.detail.class) SysUserRequest sysUserRequest) {
        return new SuccessResponseData(sysUserService.detail(sysUserRequest));
    }

    /**
     * 获取列表
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @GetResource(name = "获取列表", path = "/sysUser/list")
    public ResponseData list(SysUserRequest sysUserRequest) {
        return new SuccessResponseData(sysUserService.findList(sysUserRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhu
     * @date 2021/10/21 18:35
     */
    @GetResource(name = "分页查询", path = "/sysUser/page")
    public ResponseData page(SysUserRequest sysUserRequest) {
        return new SuccessResponseData(sysUserService.findPage(sysUserRequest));
    }

}